<template>
  <div class="cs-page">
    <!-- 按钮 -->
    <el-row style="padding-bottom: 30px">
      <el-col :span="2">
        <el-button type="danger" plain>批量删除</el-button>
      </el-col>
      <el-col :span="10" :offset="2">
        <el-input input-style="--el-input-focus-border-color: rgb(45, 216, 207);" v-model="input" placeholder="请输入学科">
          <template #append>
            <el-button type="primary" plain @click="addGrde">新增学科</el-button>
          </template>
        </el-input>
      </el-col>
    </el-row>
    <!-- 表格 -->
    <el-table :data="tableData" style="width: 100%">
      <el-table-column type="selection" width="55" />
      <el-table-column type="index" label="#" width="180" />
      <el-table-column prop="grade" label="年级" />
      <el-table-column label="操作" width="150">
        <template #default="scope">
          <el-button
            type="warning"
            size="small"
            @click="handleEdit(scope.$index, scope.row)"
            >修改</el-button
          >
          <el-button
            size="small"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      style="margin-top: 20px"
      v-model:currentPage="currentPage4"
      v-model:page-size="pageSize4"
      :page-sizes="[100, 200, 300, 400]"
      layout="total, sizes, prev, pager, next, jumper"
      :total="400"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    >
    </el-pagination>
  </div>
</template>

<script setup>
import { ref } from "vue";
import { ElMessage } from 'element-plus'
const input = ref(""),
  tableData = ref([{}, {}]),
  currentPage4 = ref(1),
  pageSize4 = ref(100);

// 自定义函数
const addGrde = () => {
  if(input.value === ''){
     ElMessage.error('学科不能为空')
  }else {
    let reg = /[^\u4E00-\u9FA5]/g
    if(!reg.test(input.value.trim())){
      let gradeInput = input.value.trim()
      console.log(gradeInput);
    }else {
      ElMessage.error('学科输入不合法,应为汉字')
    }
    
  }
};
const handleEdit = () => {};
const handleDelete = () => {};
const handleSizeChange = () => {};
const handleCurrentChange = () => {};
</script>

<style scoped>
.cs-page {
  margin-top: 30px;
}
/* .el-row {
  border-bottom: 1px solid #ccc;
} */

.cs-page >>> .el-input-group__append {
  background-color: rgb(45, 216, 207);
  color: white;
}
</style>